package com.clubs.coding.Service.Impl;

import com.clubs.coding.Service.LearningService;
import com.clubs.coding.exception.ImoocMallException;
import com.clubs.coding.exception.ImoocMallExceptionEnum;
import com.clubs.coding.model.dao.ApplicationMapper;
import com.clubs.coding.model.dao.LearningMapper;
import com.clubs.coding.model.pojo.Learning;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LearningServiceImpl implements LearningService {
 @Autowired
    ApplicationMapper applicationMapper;
 @Autowired
    LearningMapper learningMapper;
   @Override
    public PageInfo evaluate(Integer pageNum, Integer pageSize, Integer type){
        PageHelper.startPage(pageNum, pageSize);
        List<Learning> learnings = learningMapper.selectAll(type);

        PageInfo pageInfo = new PageInfo(learnings);
        pageInfo.setList(learnings);
        return pageInfo;
    }
    @Override
    //个人学习成绩
    public PageInfo userinfo(Integer pageNum, Integer pageSize, String openid){
        PageHelper.startPage(pageNum, pageSize,"null_item desc ");
        List<Learning> learnings = learningMapper.selectByOpenid(openid);

        PageInfo pageInfo = new PageInfo(learnings);
        pageInfo.setList(learnings);
        return pageInfo;
    }
    //训练记录
    @Override
    public List<Learning> count( String openid){
        List<Learning> learnings = learningMapper.selectBycount(openid);
        if (learnings.size() == 0) {
            throw new ImoocMallException(ImoocMallExceptionEnum.LEARNING_NO);
        }
        return  learnings;
    }
}
